package com.acme.task2;

/**
 * Usage:
 * java com.acme.task2.GCTest
 *     run with default number of iterations
 * java com.acme.task2.GCTest 300000
 *     explicitly specify number of iterations
 * java com.acme.task2.GCTest | java com.acme.task2.MyChart
 *     plot results instead of putting them to StdOut
 * java com.acme.task2.GCTest 300000 store
 *     specify number of iterations and enable store references mode
 *     (to show OutOfMemory error)
 */
public class GCTest {
	private static final int DEFAULT_ITERATIONS_NUM = 500000;

	public static void main(String[] args) {
		int numberOfIterations = DEFAULT_ITERATIONS_NUM;
		if (args.length > 0) numberOfIterations = Integer.parseInt(args[0]);
				
		// Store references mode -- to show OutOfMemory error
		boolean storeRefs = args.length > 1;

		test(numberOfIterations, storeRefs);
	}
	
	private static void test(int numberOfIterations, boolean storeRefs) {
		Foo[] refs = new Foo[numberOfIterations];

		for (int i = 0; i < numberOfIterations; i++) {
			if (storeRefs) {
				refs[i] = new Foo(i, true);
			} else {
				@SuppressWarnings("unused")
				Foo foo = new Foo(i, false);
			}
		}
		
		System.out.println(numberOfIterations); // Needed to use with MyChart class
	}
}
